Conversation
| return tokenAddress; | ||
| } | ||
|
|
||
| const polygonNativeTokenAddress = getNativeToken(CHAIN_ID_POLYGON); |
There was a problem hiding this comment.
Minor, could use chainId here as already verified above, and may impact other chains in future.
| }); | ||
| } | ||
|
|
||
| type NormalizeTokenAddressOptions = { |
There was a problem hiding this comment.
Since the type is very explicit, extensible and readable, could we just expose normalizeTokenAddress and remove the small wrappers?
| }); | ||
| } | ||
|
|
||
| type NormalizeTokenAddressOptions = { |
There was a problem hiding this comment.
Maybe an enum if we expose the below since we don't use the value as a string but just for branching?
| ): Promise<void> { | ||
| const { from, sourceChainId, sourceTokenAddress } = quote.request; | ||
|
|
||
| const normalizedSourceTokenAddress = normalizeTokenAddressForMM( |
There was a problem hiding this comment.
Are we safe to just do this here? Is there value in mutating the quote as soon as we get it in relay-quotes.ts so we normalize both sides in the same place?
There was a problem hiding this comment.
Yes this will be fine and still necessary. Because getLiveTokenBalance below is especially comparing the native token balance via getNativeToken utility here:
https://github.com/MetaMask/core/blob/main/packages/transaction-pay-controller/src/utils/token.ts#L312
Just to be clear, my aim was not mutating quotes so quotes are same, but the quote requests + especially this validation.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Explanation
This PR fixes Polygon native token address normalization across Relay quote/submit flows and MetaMask balance checks.
References
Fix in action:
Predict deposit
Pol_deposit.mov
Predict withdraw
Pol_withdraw.mov
Checklist
Note
Medium Risk
Medium risk because it changes how token addresses are transformed in Relay quote/submit flows and balance validation, which can impact transaction execution on Polygon; scope is limited and covered by added unit tests.
Overview
Fixes Polygon native token handling by introducing
normalizeTokenAddress(withTokenAddressTarget) to consistently map between MetaMask’s Polygon native address (0x…1010) and Relay’s native/zero-address format.Relay quote requests now normalize both source and destination token addresses before calling Relay, and Relay submit’s live balance validation normalizes the source token address before calling
getLiveTokenBalance. Tests were updated/added to cover Polygon source/target normalization and the new utility, and the changelog documents the fix.Written by Cursor Bugbot for commit 3e0e5cc. This will update automatically on new commits. Configure here.